function Save()
{
    let id=window.location.href.split('=')[1]||''
  
      let obj={     
          biaoti:$('[id=biaoti]').val(),
          zhayao:$('[id=zhayao]').val(),
          neirong:$('[id=neirong]').val(),
          fenlei:$('[id=fenlei]').val(),
          zuozhe:$('[id=zuozhe]').val(),
          shijian:$('[id=shijian]').val(),
        }
        if(id)
        {
            $.ajax(
                {
                    url:`http://127.0.0.1:8080/product/${id}`,
                    type:'PUT',
                    data:obj,
                    success:function(res)
                    {
                        window.location.href='./index.html'

                    }
                })
        }
        else
        {
            $.post(`http://127.0.0.1:8080/product`,obj,function(res)
            {
                window.location.href='./index.html'
            })
        }
                
    
}
function Delete(id)
{
    $.ajax(
        {
            url:`http://127.0.0.1:8080/product/${id}`,
            type:'Delete',
            success:function(res)
            {
                window.location.href=`./index.html`
            }
        })

}
function Bark()
{
    window.location.href=`./index.html`

}
function Install()
{
    window.location.href='./edit.html'

}
function Update(id)
{
    window.location.href=`./edit.html?id=${id}`

}
function Query()
{
    let keyword=$('[name=text]').val()
    let tb=$('table')
    tb.html(
        `
        <tr>
        <input type="button" value="添加" onclick="Install()">
        <input type="text" name="text">
        <input type="button" value="查找" onclick="Query()">
        </tr>
        <tr>
            <td>id</td>
            <td>标题</td>
            <td>摘要</td>
            <td>内容</td>
            <td>分类</td>
            <td>作者</td>
            <td>发表时间</td>
            <td>操作</td>
        </tr>
        `)
        $.get(`http://127.0.0.1:8080/product?keyword=${keyword}`,function(res)
        {
            res.forEach(item => {
                tb.append(
                    `
                    <tr>
                    <td>${item.id}</td>
                    <td>${item.biaoti}</td>
                    <td>${item.zhayao}</td>
                    <td>${item.neirong}</td>
                    <td>${item.fenlei}</td>
                    <td>${item.zuozhe}</td>
                    <td>${item.shijian}</td>
                    <td><input type="button" value="修改" onclick="Update(${item.id})"></td>
                    <td><input type="button" value="删除" onclick="Delete(${item.id})"></td>
                </tr>
                    

                    `)
                
            });

        })




}